package com.industrial.app.controller;

import com.industrial.app.domain.formal.FourGyPower;
import com.industrial.app.service.IFourGyPowerService;
import com.industrial.common.core.utils.poi.ExcelUtil;
import com.industrial.common.core.web.controller.BaseController;
import com.industrial.common.core.web.domain.AjaxResult;
import com.industrial.common.core.web.page.TableDataInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.util.List;


/**
 * 4省工业用电Controller
 *
 * @author ruoyi
 * @date 2024-01-22
 */
@RestController
@RequestMapping("/biz/power/zdsyd")
public class FourGyPowerController extends BaseController
{
    @Autowired
    private IFourGyPowerService fourGyPowerService;

    /**
     * 查询4省工业用电列表
     */
//    @PreAuthorize("@ss.hasPermi('system:power:list')")
    @GetMapping("/list")
    public TableDataInfo list(FourGyPower fourGyPower)
    {
        startPage();
        List<FourGyPower> list = fourGyPowerService.selectFourGyPowerList(fourGyPower);
        return getDataTable(list);
    }

    /**
     * 导出4省工业用电列表
     */
//    @PreAuthorize("@ss.hasPermi('system:power:export')")
//    @Log(title = "4省工业用电", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, FourGyPower fourGyPower)
    {
        List<FourGyPower> list = fourGyPowerService.selectFourGyPowerList(fourGyPower);
        ExcelUtil<FourGyPower> util = new ExcelUtil<FourGyPower>(FourGyPower.class);
        util.exportExcel(response, list, "4省工业用电数据");
    }

    /**
     * 获取4省工业用电详细信息
     */
//    @PreAuthorize("@ss.hasPermi('system:power:query')")
    @GetMapping(value = "/{baseId}")
    public AjaxResult getInfo(@PathVariable("baseId") String baseId)
    {
        return success(fourGyPowerService.selectFourGyPowerByBaseId(baseId));
    }

    /**
     * 新增4省工业用电
     */
//    @PreAuthorize("@ss.hasPermi('system:power:add')")
//    @Log(title = "4省工业用电", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FourGyPower fourGyPower)
    {
        return toAjax(fourGyPowerService.insertFourGyPower(fourGyPower));
    }

    /**
     * 修改4省工业用电
     */
//    @PreAuthorize("@ss.hasPermi('system:power:edit')")
//    @Log(title = "4省工业用电", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FourGyPower fourGyPower)
    {
        return toAjax(fourGyPowerService.updateFourGyPower(fourGyPower));
    }

    /**
     * 删除4省工业用电
     */
//    @PreAuthorize("@ss.hasPermi('system:power:remove')")
//    @Log(title = "4省工业用电", businessType = BusinessType.DELETE)
    @DeleteMapping("/{baseIds}")
    public AjaxResult remove(@PathVariable String[] baseIds)
    {
        return toAjax(fourGyPowerService.deleteFourGyPowerByBaseIds(baseIds));
    }

    @PostMapping("/importExcelFile")
    public AjaxResult importExcelFile(@RequestPart("file")MultipartFile file){
        return fourGyPowerService.importExcelFile(file);
    }

    /**
     * <p>
     *     清空所有的4省工业用电数据
     * </p>
     * @return
     */
    @DeleteMapping("/clearAllTableData")
    public AjaxResult clearAllTableData(){
        fourGyPowerService.clearAllTableData();
        return AjaxResult.success();
    }

    /**
     * <p>
     *     将临时表中的数据迁移到正式表虽
     * </p>
     * @return
     */
    @PostMapping("/transferDataInOneClick")
    public AjaxResult transferDataInOneClick(){
        return toAjax(fourGyPowerService.transferDataInOneClick());
    }
}
